package game;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Point2D;

public class CapacitorManager 
{
	private static CapacitorManager instance;
	
	public Capacitor capacitor1 = null;
	public Capacitor capacitor2 = null;
	public Capacitor baseCapacitor;
	
	public int minEnimie = 10;
	public int maxEnimie = 20;
	
	
	
	public static CapacitorManager getInstance()
	{
		if(instance == null)
			instance = new CapacitorManager();
		return instance;
	}
	
	
	private CapacitorManager()
	{ 
		Reiniciar();
		ZerarBaseCapacitor();
	}
	
	
	public void Update(Player player)
	{

		
		
		if(capacitor1 != null)
		{
			capacitor1.Update();
			
			if(player.getRectangle().intersects(capacitor1.getRectangle()) &&
					capacitor1.coletado == false)
			{
				Audios.getInstance().Play(6);
				capacitor1.coletado = true;
			}
			if(capacitor1.coletado == true)
			{
				capacitor1.setPosition(new Point2D.Double(
						Player.hud.getPosition().getX() + 80,
						Player.hud.getY() + 68)
				);
			}
			
		}
		if(capacitor2 != null)
		{
			capacitor2.Update();
			
			if(player.getRectangle().intersects(capacitor2.getRectangle()) &&
					capacitor2.coletado == false)
			{
				Audios.getInstance().Play(6);
				capacitor2.coletado = true;
			}
			if(capacitor2.coletado == true)
			{
				capacitor2.setPosition(new Point2D.Double(
						Player.hud.getPosition().getX() + 122,
						Player.hud.getY() + 68)
				);
			}
		}
		baseCapacitor.Update();
	}
	
	public void Draw(Graphics2D g2d)
	{
		baseCapacitor.draw(g2d);
		
		if(capacitor1 != null)
			capacitor1.draw(g2d);
		if(capacitor2 != null)
			capacitor2.draw(g2d);
	}
	
	public void addCapacitor(Point pos)
	{
		if(capacitor1 == null)
		{
			capacitor1 = new Capacitor(pos, new Point(40, 15));
			capacitor1.setImage(68);
		}
		else if(capacitor2 == null)
		{
			capacitor2 = new Capacitor(pos, new Point(40, 15));
			capacitor2.setImage(69);
		}
	}

	public void ZerarBaseCapacitor()
	{
		switch(SceneManager.getLevel())
		{
			case 1:
				baseCapacitor = new Capacitor(new Point(700, 600), new Point(80, 80));
				break;
				
			case 2:
				baseCapacitor = new Capacitor(new Point(740, 420), new Point(80, 80));
				break;
				
			case 3:
				baseCapacitor = new Capacitor(new Point(960, 200), new Point(80, 80));
				break;
				
			case 4:
				baseCapacitor = new Capacitor(new Point(800, 1160), new Point(80, 80));
				break;
				
			case 5:
				baseCapacitor = new Capacitor(new Point(1520, 560), new Point(80, 80));
				break;
		}
		baseCapacitor.setImage(70);
	}
	
	public void Reiniciar()
	{
		capacitor1 = null;
		capacitor2 = null;
			
	}
}
